package com.hr.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hr.service.IDepartmentService;
import com.hr.vo.ResultSet;

@RestController
@RequestMapping("/department")
public class DepartmentController extends BaseController {
	private final Logger logger = Logger.getLogger(getClass());
    @Autowired
    private DiscoveryClient client;
    
    @Autowired 
	private IDepartmentService departmentService;

    @ResponseBody
    @RequestMapping(value="list",method = {RequestMethod.GET})
    public ResultSet listAll() {
        List<ServiceInstance> instances = client.getInstances("deptrtment-list-service");
        for (int i = 0; i < instances.size(); i++) {
            logger.info("/list,host:" + instances.get(i).getHost() + ",service_id:" + instances.get(i).getServiceId());
        }
        return departmentService.listAll();
    }

}
